<template>
  <PageContainer>
    <view class="container">
      <Header title="业务结果" />
      <TResult types="waiting" :title="title" :content="content" cancel-text="供需详情">
        <template #button>
          <view class="disFlxAC py-10">
            <TButton
              text="供需详情"
              :customStyle="{
                minWidth: '176rpx',
                height: '64rpx',
                color: '#2878FF',
                lineHeight: '60rpx',
                border: 'solid 1px #2878FF',
                borderRadius: '64rpx',
                backgroundColor: '#FFF',
              }"
              @click="handleCancel"
            ></TButton>
            <TButton
              :text="confirmText"
              class="ml-12"
              :customStyle="{
                minWidth: '176rpx',
                height: '64rpx',
                color: '#FFF',
                lineHeight: '60rpx',
                border: 'solid 1px #2878FF',
                borderRadius: '64rpx',
                backgroundColor: '#2878FF',
              }"
              openType="share"
            ></TButton>
            <TButton
              text="联系审核人"
              class="ml-12"
              :customStyle="{
                minWidth: '176rpx',
                height: '64rpx',
                color: '#FFF',
                lineHeight: '60rpx',
                border: 'solid 1px #2878FF',
                borderRadius: '64rpx',
                backgroundColor: '#2878FF',
              }"
              @click="openPopup"
            ></TButton>
          </view>
        </template>
      </TResult>
    </view>
  </PageContainer>

  <UniPopup ref="phoneCallPopup">
    <view class="phoneCall-info">
      <text class="title">联系审核人</text>
      <text class="desc">可通过以下电话联系供需审核人</text>
      <view class="phoneCall-info_item_box">
        <template v-for="v in reviewSysUserList" :key="v.id">
          <view class="phoneCall-info_item font-bold" @click="callPhone(v.phone)">
            <text>{{ v.userName }}</text>
            <text class="phoneCall-info_phone">
              {{ v.phone }}
            </text>
          </view>
        </template>
      </view>
      <view class="btn" @click="closePopup()">关闭</view>
    </view>
  </UniPopup>
</template>

<script lang="ts" setup>
  /* releaseBoResult 发布供需结果页 */
  import Header from '@/components/Header/index.vue';
  import PageContainer from '@/components/PageContainer/index.vue';
  import TResult from '@/components/TResult/index.vue';
  import { useAppShare } from '@/hooks/core/useAppShare';
  import { onLoad, redirectTo } from '@/router';
  import type { ReleaseBoResult } from '@/router/types/modules';
  import { useUserStore } from '@/store/modules/user';
  import { onShareAppMessage } from '@dcloudio/uni-app';
  import { getCurrentInstance, ref } from 'vue';
  import UniPopup from '@/uni_modules/uni-popup/components/uni-popup/uni-popup.vue';
  import TButton from '@/components/TButtonGroup/TButton.vue';
  import { getReviewSysUserList } from '@/api/businessOpportunities';
  import type { IReviewSysUserListResult } from '@/api/businessOpportunities/type';
  import { Toast } from '@/utils';

  const { setWxSharePath } = useAppShare();
  const { userInfo } = useUserStore();
  const routeOptions = ref<ReleaseBoResult>();
  const confirmText = ref<string>();
  const title = ref<string>();
  const content = ref<string>();
  const reviewSysUserList = ref<IReviewSysUserListResult[]>([]);

  onLoad<'releaseBoResult'>((op) => {
    wx.hideShareMenu({
      menus: ['shareAppMessage', 'shareTimeline'],
    });
    routeOptions.value = op;

    getReviewSysUserList({ reviewRecordId: op.reviewRecordId }).then(
      (res) => (reviewSysUserList.value = res),
    );

    title.value = '审核中';
    content.value =
      '供需信息需要经过管理员审核通过后才可发布成功。您也可以邀请管理员帮你快速审核哦~';
    confirmText.value = '邀请秘书处审核';
  });

  function handleCancel() {
    // 跳转意向详情
    redirectTo({
      name: 'supplyDemandDetails',
      options: {
        id: routeOptions.value!.id,
      },
    });
  }

  const _this = getCurrentInstance();
  const openPopup = (direction: string = 'center') => {
    (_this?.refs['phoneCallPopup'] as any).open(direction);
  };

  const closePopup = (direction: string = 'center') => {
    (_this?.refs['phoneCallPopup'] as any).close(direction);
  };

  /** 拨打电话 */
  function callPhone(phoneNumber: string) {
    uni.makePhoneCall({ phoneNumber });
  }

  onShareAppMessage(() => {
    return {
      title: `${userInfo.userName}正在申请发布供需信息，秘书处管理员快来帮我审核吧~`,
      path: setWxSharePath({
        name: 'businessOpportunitieAuditDetail',
        options: { id: routeOptions.value?.reviewRecordId! },
      }),
      imageUrl:
        'https://hb-saas.obs.cn-south-1.myhuaweicloud.com/mall/saas/Invitation-handling.png',
    };
  });
</script>

<style lang="scss" scoped>
  .phoneCall-info {
    box-sizing: border-box;
    width: 622rpx;
    border-radius: 32rpx;
    background-color: #fff;
    padding: 48rpx 48rpx 32rpx 48rpx;
    display: flex;
    align-items: center;
    flex-direction: column;
    justify-content: space-around;
    .title {
      color: #333;
      text-align: center;
      font-size: 32rpx;
      font-weight: 400;
      line-height: 48rpx;
      font-weight: bold;
    }
    .desc {
      color: #333;
      text-align: center;
      font-size: 28rpx;
      font-weight: 400;
      line-height: 40rpx;
      margin: 24rpx 0 32rpx 0;
    }
    .phoneCall-info_item_box {
      width: 100%;
      max-height: 400rpx;
      overflow-y: scroll;

      .phoneCall-info_item {
        width: 100%;
        box-sizing: border-box;
        display: flex;
        align-items: center;
        justify-content: space-between;
        font-size: 32rpx;
        color: #333;
        padding: 24rpx 20rpx;
        background-color: #f7f8fa;
        margin-top: 20rpx;
        border-radius: 16rpx;
      }
      .phoneCall-info_phone {
        color: #4a75ff;
      }
    }

    .btn {
      margin-top: 32rpx;
      box-sizing: border-box;
      display: flex;
      width: 100%;
      height: 72rpx;
      padding: 8px 0px;
      justify-content: center;
      align-items: center;
      border-radius: 32rpx;
      background: #2878ff;
      color: #fff;
      font-size: 28rpx;
    }
  }
</style>
